package org.example.wx_springboot.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.wx_springboot.common.Result;
import org.example.wx_springboot.controller.request.DeliveryRequest;
import org.example.wx_springboot.controller.request.OrderdataRequest;
import org.example.wx_springboot.entity.Orderdata;
import org.example.wx_springboot.entity.Shoppingcart;
import org.example.wx_springboot.service.IOrderdataService;
import org.example.wx_springboot.service.IShoppingcartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin//这个注解是解决跨域错误的
@RestController
@Slf4j
@RequestMapping("/orderdata")
public class OrderdataConttroller {
    @Autowired
    IOrderdataService orderdataService;


    @GetMapping("/list")
    public Result list(){
        List<Orderdata> orderdata = orderdataService.list();
        return Result.success(orderdata);//返回CommodityMapper的数据
    }


    @PostMapping("/seve")
    public Result save(@RequestBody Orderdata orderdata){
        orderdataService.save(orderdata);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        orderdataService.deleteById(id);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Orderdata obj){
        orderdataService.update(obj);
        return Result.success();
    }

    //    模糊查询
    @GetMapping("/page")
    //    将查询类放进来，放进来后去CommodityService将name和phone拿出来
    public Result page(OrderdataRequest OrderdataPageRequest) {
//        配置完去ICommodityService实践一下
        return Result.success(orderdataService.page(OrderdataPageRequest));
    }


}
